package Date_Calendar;

import java.util.Calendar;

public class Example4 {
    public static void main(String[] args) {
        //演示 : 获取Calender类的字段
        //1.获取Calendar类实例
        Calendar calendar = Calendar.getInstance();

        //2.调用get方法
        System.out.println("year = " + calendar.get(Calendar.YEAR));
        System.out.println("month = " + (calendar.get(Calendar.MONTH) + 1));
        System.out.println("day = " + calendar.get(Calendar.DAY_OF_MONTH));
        System.out.println("hour = " + calendar.get(Calendar.HOUR_OF_DAY));
        System.out.println("minute = " + calendar.get(Calendar.MINUTE));
        System.out.println("second = " + calendar.get(Calendar.SECOND));
        System.out.println("-------------------------------");

        //3.自由组合
        System.out.print("Calendar = ");
        System.out.println(calendar.get(Calendar.YEAR) + "年" +
                (calendar.get(Calendar.MONTH) + 1) + "月" +
                calendar.get(Calendar.DAY_OF_MONTH) + "日" +
                calendar.get(Calendar.HOUR_OF_DAY) + ":" +
                calendar.get(Calendar.MINUTE) + ":" +
                calendar.get(Calendar.SECOND));
    }
}
